// 导入获取树形结构数据的方法
import { companyDepartments } from '@/api/departments'
// 将数组转为树形结构
 import { treeChange } from '@/utils'
const state = {
  // 头部数据
  topData: {},
  // 树形结构的数据
  treeData: [],
  // 请求获取到的原数据
  resData: []
}
const mutations = {
  setTopData (state, value) {
    state.topData = value
  },
  setTreeData (state, value) {
    state.treeData = value
  },
  setResData (state, value) {
    state.resData = value
  }
}
const actions = {
  async getTreeData (store) {
    const res = await companyDepartments()
    store.commit('setTopData', {
      name: '江苏传智',
      manager: '负责人',
      id: '',
      children: []
    })
    store.commit('setResData', res.depts)
    store.commit('setTreeData', treeChange(res.depts, ''))
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
